if(typeof(MyLiveChat)=="undefined")
{
	MyLiveChat={};
	MyLiveChat.PageBeginTime=new Date().getTime();
	MyLiveChat.LoadingHandlers=[];
	//	,"Departments"
	MyLiveChat.CPRFIELDS=["SyncType","SyncStatus","SyncResult","HasReadyAgents","VisitorUrls","VisitorStatus","VisitorDuration","VisitorEntryUrl","VisitorReferUrl"];
}

MyLiveChat.Version=1010;
MyLiveChat.FirstRequestTimeout=2000;
MyLiveChat.NextRequestTimeout=8000;
MyLiveChat.SyncType=''
MyLiveChat.SyncStatus="LOADING";
MyLiveChat.SyncUserName=null;
MyLiveChat.SyncResult="LOADING";
MyLiveChat.HasReadyAgents=true;
MyLiveChat.SourceUrl="";

MyLiveChat.Departments=[];

MyLiveChat.Departments.push({
	Name:"Default",
	Agents:[{
		Id:'User:1',
		Name:'Ahmad Sapei (admin)',
		Online:true
	}],
	Online:true
});


//the visitor properties will be set after sync
MyLiveChat.VisitorUrls=[];



MyLiveChat.VisitorStatus="";
MyLiveChat.VisitorDuration=0;
MyLiveChat.VisitorEntryUrl="";
MyLiveChat.VisitorReferUrl="";

MyLiveChat.PrivateChatUrl=null;

MyLiveChat.HCCID='52418180';
MyLiveChat.ShowButton=true;
MyLiveChat.ShowLink=true;
MyLiveChat.ShowBox=true;
MyLiveChat.ShowInvite=true;
MyLiveChat.ShowSmart=false;
MyLiveChat.ScriptUrl="https://chat1.mylivechat.com/livechat/livechat.aspx?hccid=52418180\x26apimode=chatapi\x26SmartVisible=0";
MyLiveChat.SiteUrl="https://chat1.mylivechat.com/";
MyLiveChat.UrlBase="https://chat1.mylivechat.com/livechat/";
MyLiveChat.HomePage=MyLiveChat.UrlBase.replace(/\/\/[a-z0-9]+\.([^\/]+\/).*$/gi,"//www.$1");

MyLiveChat.RandomID='fb970113-92c7-41b2-aa36-a1045058cae5';


MyLiveChat.FeedbackBehavior=''||"Show";
MyLiveChat.FeedbackRedirectUrl=''||"";

MyLiveChat.ButtonOnlineTooltip=null||"";
MyLiveChat.ButtonOfflineTooltip=null||"";
MyLiveChat.ButtonOnlineImage=''||"1";
MyLiveChat.ButtonOfflineImage=''||"1";
if(MyLiveChat.ButtonOnlineImage=="upload")
	MyLiveChat.ButtonOnlineImage=MyLiveChat.SiteUrl+"Customization/Customer/"+MyLiveChat.HCCID+"/ButtonOnlineImage.gif";
else
	MyLiveChat.ButtonOnlineImage=MyLiveChat.SiteUrl+"Customization/Template/ButtonOnlineImage_"+MyLiveChat.ButtonOnlineImage+".gif";
if(MyLiveChat.ButtonOfflineImage=="upload")
	MyLiveChat.ButtonOfflineImage=MyLiveChat.SiteUrl+"Customization/Customer/"+MyLiveChat.HCCID+"/ButtonOfflineImage.gif";
else
	MyLiveChat.ButtonOfflineImage=MyLiveChat.SiteUrl+"Customization/Template/ButtonOfflineImage_"+MyLiveChat.ButtonOfflineImage+".gif";

MyLiveChat.ButtonOnlineImage=MyLiveChat.ButtonOnlineImage+"?"+MyLiveChat.Version;
MyLiveChat.ButtonOfflineImage=MyLiveChat.ButtonOfflineImage+"?"+MyLiveChat.Version;


MyLiveChat.LinkOnlineTooltip=null||"";
MyLiveChat.LinkOfflineTooltip=null||"";
MyLiveChat.LinkOnlineCode=null||"Click here to chat";
MyLiveChat.LinkOfflineCode=null||"Click here to leave a message";

MyLiveChat.BoxOnlineCode=null||"Online";
MyLiveChat.BoxOfflineCode=null||"Leave a message";
MyLiveChat.BoxOnlineTooltip=null||"";
MyLiveChat.BoxOfflineTooltip=null||"";
MyLiveChat.BoxPrompt="Type your question here and click below...";
MyLiveChat.BoxMessage=null||MyLiveChat.BoxPrompt;
MyLiveChat.BoxOnlinePhoto=''||"1";
MyLiveChat.BoxOfflinePhoto=''||"1";
if(MyLiveChat.BoxOnlinePhoto=="upload")
	MyLiveChat.BoxOnlinePhoto=MyLiveChat.SiteUrl+"Customization/Customer/"+MyLiveChat.HCCID+"/BoxOnlinePhoto.gif";
else
	MyLiveChat.BoxOnlinePhoto=MyLiveChat.SiteUrl+"Customization/Template/BoxOnlinePhoto_"+MyLiveChat.BoxOnlinePhoto+".gif";
if(MyLiveChat.BoxOfflinePhoto=="upload")
	MyLiveChat.BoxOfflinePhoto=MyLiveChat.SiteUrl+"Customization/Customer/"+MyLiveChat.HCCID+"/BoxOfflinePhoto.gif";
else
	MyLiveChat.BoxOfflinePhoto=MyLiveChat.SiteUrl+"Customization/Template/BoxOfflinePhoto_"+MyLiveChat.BoxOfflinePhoto+".gif";

MyLiveChat.BoxOnlinePhoto=MyLiveChat.BoxOnlinePhoto+"?"+MyLiveChat.Version;
MyLiveChat.BoxOfflinePhoto=MyLiveChat.BoxOfflinePhoto+"?"+MyLiveChat.Version;

MyLiveChat.DialogWidth=parseInt('580')||580;
MyLiveChat.DialogHeight=parseInt('420')||420;
MyLiveChat.DialogOption = "status=1,width="+MyLiveChat.DialogWidth+",height="+MyLiveChat.DialogHeight+",resizable=1";
MyLiveChat.DialogOption+=",left="+Math.floor((screen.availWidth-MyLiveChat.DialogWidth)/2)
MyLiveChat.DialogOption+=",top="+Math.floor((screen.availHeight-MyLiveChat.DialogHeight)/2)

MyLiveChat.PopupBlockedMsg="Pop-up blocker detected.";

MyLiveChat.InviteTemplate=''||"1";
MyLiveChat.InvitePosition=''||"middlecenter";
MyLiveChat.InviteStartPos=''||"topcenter";
MyLiveChat.InviteOffsetX=parseInt('')||0;
MyLiveChat.InviteOffsetY=parseInt('')||-100;
MyLiveChat.InvitePhoto='7'||"1";
MyLiveChat.InviteHeadline="Chat Invitation"||"Chat Invitation";
MyLiveChat.InviteMessage="Hallo, nama saya (AGENT). Ada yang bisa saya bantu?"||"Hello, my name is (AGENT). How may I help you today?";

if(MyLiveChat.InvitePhoto=="upload")
	MyLiveChat.InvitePhoto=MyLiveChat.SiteUrl+"Customization/Customer/"+MyLiveChat.HCCID+"/InvitePhoto.gif";
else
	MyLiveChat.InvitePhoto=MyLiveChat.SiteUrl+"Customization/Template/InvitePhoto_"+MyLiveChat.InvitePhoto+".gif";

MyLiveChat.InvitePhoto=MyLiveChat.InvitePhoto+"?"+MyLiveChat.Version;

MyLiveChat.InviteUseAgentPhoto=false;

MyLiveChat.InviteAcceptText=null||"Chat Now";
MyLiveChat.InviteRejectText=null||"No Thanks";

MyLiveChat.InviteShowTimeout=parseInt('30')||0;

MyLiveChat.SmartTemplate=''||"1";
MyLiveChat.SmartPosition=''||"bottomright";
MyLiveChat.SmartStartPos=''||"topright";
MyLiveChat.SmartOffsetX=parseInt('')||0;
MyLiveChat.SmartOffsetY=parseInt('')||0;
MyLiveChat.SmartCondition=''||"always";
MyLiveChat.SmartPhoto='9'||"1";
MyLiveChat.SmartHeadline="Chat Invitation"||"Chat Invitation";
MyLiveChat.SmartMessage="Ada yang bisa saya bantu ?"||"May I help you?";

MyLiveChat.SmartShowDepartments=''||"All";
MyLiveChat.SmartClickOfflineItem=''||"PreChat";
MyLiveChat.SmartShowOfflineText=null||"";
		
if(MyLiveChat.SmartPhoto=="upload")
	MyLiveChat.SmartPhoto=MyLiveChat.SiteUrl+"Customization/Customer/"+MyLiveChat.HCCID+"/SmartPhoto.gif";
else
	MyLiveChat.SmartPhoto=MyLiveChat.SiteUrl+"Customization/Template/SmartPhoto_"+MyLiveChat.SmartPhoto+".gif";
	
MyLiveChat.SmartPhoto=MyLiveChat.SmartPhoto+"?"+MyLiveChat.Version;

MyLiveChat.SmartAcceptText=null||"Chat Now";
MyLiveChat.SmartRejectText=null||"No Thanks";

MyLiveChat.SmartPhotoWidth=128;


MyLiveChat.SmartMaxReject=parseInt("2")||2;
MyLiveChat.SmartUseMaxReject=("0"!='1');
MyLiveChat.SmartMaxIgnore=parseInt("2")||2;
MyLiveChat.SmartUseMaxIgnore=("0"!='1');
MyLiveChat.SmartHideTimeout=60 * (parseInt("10")||10);
MyLiveChat.SmartUseHideTimeout=("0"!='1');
if(!MyLiveChat.SmartUseHideTimeout)
{
	MyLiveChat.SmartHideTimeout=0;
}
MyLiveChat.SmartShowTimeout=parseInt("60")||60;

MyLiveChat.SmartUseShowTimeout=("0"!='1');
MyLiveChat.SmartHideIfChatting=("0"!='1');
MyLiveChat.SmartPlaySound=("0"!='0');
MyLiveChat.SmartSoundFile=parseInt("1")||1;
MyLiveChat.SmartUsePageCount=("0"!='1');
MyLiveChat.SmartPageCount=parseInt("5")||5;
MyLiveChat.SmartUsePageTime=("0"!='1');
MyLiveChat.SmartPageTime=parseInt("30")||30;
MyLiveChat.SmartUseStayTime=("0"!='1');
MyLiveChat.SmartStayTime=parseInt("120")||120;
MyLiveChat.SmartUseVisitUrlFilter=("0"!='1');
MyLiveChat.SmartVisitUrlFilter=""
MyLiveChat.SmartUseEntryUrlFilter=("0"!='1');
MyLiveChat.SmartEntryUrlFilter=""
MyLiveChat.SmartUseReferUrlFilter=("0"!='1');
MyLiveChat.SmartReferUrlFilter=""
MyLiveChat.SmartUseKeywordsFilter=("0"!='1');
MyLiveChat.SmartKeywordsFilter=""

MyLiveChat.SmartAcceptTooltip="Chat Invitation"
MyLiveChat.SmartRejectTooltip="Close"

MyLiveChat.InviteAcceptTooltip="Chat Invitation"
MyLiveChat.InviteRejectTooltip="Close"
MyLiveChat.InvitePlaySound = ("0"!='0');
MyLiveChat.InviteSoundFile='1'||"1";


MyLiveChat.InPageTemplate='1'||"1";
MyLiveChat.InPagePosition='bottomright'||"bottomright";
MyLiveChat.InPageStartPos=''||"bottomright";
MyLiveChat.InPageOffsetX=parseInt('')||0;
MyLiveChat.InPageOffsetY=parseInt('')||0;
MyLiveChat.InPageHeadBgColor='#FF0000'||"";
MyLiveChat.InPageHeadBorderColor='#FF0000'||"";
MyLiveChat.InPageHeadBorderWidth=''||"1";
MyLiveChat.InPageHeadColor='#000000'||"white";
MyLiveChat.InPageHeadFont='Arial'||"";
MyLiveChat.InPageHeadOffline=null||"";
MyLiveChat.InPageHeadOnline=null||"";
MyLiveChat.InPageHeadSize='16px'||"15px";
MyLiveChat.InPageImageOnline = '1'||"1";
MyLiveChat.InPageImageOffline = '1'||"1";
MyLiveChat.InPageImageUrlOnline = ''||"";
MyLiveChat.InPageImageUrlOffline = ''||"";
if(MyLiveChat.InPageImageOnline!="custom")
   	MyLiveChat.InPageImageUrlOnline=MyLiveChat.SiteUrl+"Customization/Template/InPageImageOnline_"+MyLiveChat.InPageImageOnline+".png";
if(MyLiveChat.InPageImageOffline!="custom")
	MyLiveChat.InPageImageUrlOffline=MyLiveChat.SiteUrl+"Customization/Template/InPageImageOffline_"+MyLiveChat.InPageImageOffline+".png";
MyLiveChat.InPageBubbleTopClosed = false;
MyLiveChat.InPageUseBubbleTop = '0'=="1";
MyLiveChat.InPageBubbleTop = '1'||"1";
MyLiveChat.InPageBubbleTopUrl = ''||"";
if(MyLiveChat.InPageBubbleTop!="custom")
	MyLiveChat.InPageBubbleTopUrl=MyLiveChat.SiteUrl+"Customization/Template/InPageBubbleTop_"+MyLiveChat.InPageBubbleTop+".png";

MyLiveChat.WidgetStartPos=''||"middleleft";
MyLiveChat.WidgetPosition=''||"middleleft";
MyLiveChat.WidgetOffsetX=parseInt('')||0;
MyLiveChat.WidgetOffsetY=parseInt('')||0;
//if(isNaN(MyLiveChat.WidgetOffsetX))MyLiveChat.WidgetOffsetX=-80;
//if(isNaN(MyLiveChat.WidgetOffsetY))MyLiveChat.WidgetOffsetY=-120;
MyLiveChat.WidgetHoverOffsetX=parseInt('')||0;
MyLiveChat.WidgetHoverOffsetY=parseInt('')||MyLiveChat.WidgetOffsetY;
MyLiveChat.WidgetBodyPadding=parseInt('')||0;
MyLiveChat.WidgetOnlineImage=''||'1';
MyLiveChat.WidgetOfflineImage=''||'1';
MyLiveChat.WidgetOnlineImageUrl=''||'';
MyLiveChat.WidgetOfflineImageUrl=''||'';
MyLiveChat.WidgetHoverOnlineImage=''||'1';
MyLiveChat.WidgetHoverOfflineImage=''||'1';
MyLiveChat.WidgetHoverOnlineImageUrl=''||'';
MyLiveChat.WidgetHoverOfflineImageUrl=''||'';
if(MyLiveChat.WidgetOnlineImage!="custom")
	MyLiveChat.WidgetOnlineImageUrl=MyLiveChat.SiteUrl+"Customization/Template/WidgetOnlineImage_"+MyLiveChat.WidgetOnlineImage+".png";
if(MyLiveChat.WidgetOfflineImage!="custom")
	MyLiveChat.WidgetOfflineImageUrl=MyLiveChat.SiteUrl+"Customization/Template/WidgetOfflineImage_"+MyLiveChat.WidgetOfflineImage+".png";
if(MyLiveChat.WidgetHoverOnlineImage!="custom")
	MyLiveChat.WidgetHoverOnlineImageUrl=MyLiveChat.SiteUrl+"Customization/Template/WidgetHoverOnlineImage_"+MyLiveChat.WidgetHoverOnlineImage+".png";
if(MyLiveChat.WidgetHoverOfflineImage!="custom")
	MyLiveChat.WidgetHoverOfflineImageUrl=MyLiveChat.SiteUrl+"Customization/Template/WidgetHoverOfflineImage_"+MyLiveChat.WidgetHoverOfflineImage+".png";



(function(){
	if(MyLiveChat.localStorage||MyLiveChat.userDataBehavior)
		return;
	if(/MSIE [678]\./.test(navigator.userAgent))
	{
		var inp=document.createElement("input");
		inp.setAttribute("type","hidden");
		document.body.appendChild(inp);
		MyLiveChat.userDataBehavior = inp;
        MyLiveChat.userDataBehavior.style.behavior="url('#default#userData')";
	}
	MyLiveChat.localStorage = window.localStorage;
	
})();

function MyLiveChat_LoadUserDataBehavior(name) {
	try
	{
		MyLiveChat.userDataBehavior.load("mlc-"+MyLiveChat.HCCID+"-"+name);
		return true;
	}
	catch(x)
	{
		return false;
	}
}

function MyLiveChat_SupportLocalData()
{
	if(MyLiveChat_LoadUserDataBehavior("any"))
		return "userDataBehavior";
	if(MyLiveChat.localStorage)
		return "localStorage";
}

function MyLiveChat_GetLocalData(name)
{
    if (MyLiveChat_LoadUserDataBehavior(name)) {
		var nam=MyLiveChat.userDataBehavior.getAttribute("n");
		if(nam!=name)
			return null;
        var val=MyLiveChat.userDataBehavior.getAttribute("v");
        var exp=MyLiveChat.userDataBehavior.getAttribute("e");
        if(exp&&new Date().getTime()>parseInt(exp))
			return null;
		return val;
    }
	if (MyLiveChat.localStorage) {
        var val=MyLiveChat.localStorage.getItem("mlcv-"+MyLiveChat.HCCID+"-" + name);
        var exp=MyLiveChat.localStorage.getItem("mlce-"+MyLiveChat.HCCID+"-" + name);
        if(exp&&new Date().getTime()>exp)
			return null;
		return val;
    }

	var cookies=document.cookie.split(';');
	for(var i=0;i<cookies.length;i++)
	{
		var parts=cookies[i].split('=');
		if(name==parts[0].replace(/\s/g,''))
			return unescape(parts[1])
	}
}
function MyLiveChat_SetLocalData(name,value,seconds)
{
    if (MyLiveChat_LoadUserDataBehavior()) {
		MyLiveChat.userDataBehavior.setAttribute("n", name);
		if(value)
			MyLiveChat.userDataBehavior.setAttribute("v", value);
		else
			MyLiveChat.userDataBehavior.removeAttribute("v");
        if(seconds)
			MyLiveChat.userDataBehavior.setAttribute("e", String(new Date().getTime()+seconds*1000));
		else
			MyLiveChat.userDataBehavior.removeAttribute("e");
        MyLiveChat.userDataBehavior.save("mlc-"+MyLiveChat.HCCID+"-"+name);
        return;
    }
	if (MyLiveChat.localStorage) {
		if(value)
			MyLiveChat.localStorage.setItem("mlcv-"+MyLiveChat.HCCID+"-" + name, value);
		else
			MyLiveChat.localStorage.removeItem("mlcv-"+MyLiveChat.HCCID+"-" + name);
        if(seconds)
			MyLiveChat.localStorage.setItem("mlce-"+MyLiveChat.HCCID+"-" + name, String(new Date().getTime()+seconds*1000));
		else
			MyLiveChat.localStorage.removeItem("mlce-"+MyLiveChat.HCCID+"-" + name);
        return;
    }
    
	var cookie=name+"="+escape(value)+"; path=/;";
	if(seconds)
	{
		var d=new Date();
		d.setSeconds(d.getSeconds()+seconds);
		cookie+=" expires="+d.toUTCString()+";";
	}
	document.cookie=cookie;
}


function MyMyLiveChat_SmartTriggers()
{
	//for this page
	if(MyLiveChat.SmartAccepted)
		return false;
	if(MyLiveChat.SmartRejected)
		return false;
	
	if(MyLiveChat.SmartHideIfChatting)
	{	
		if(MyLiveChat.VisitorStatus!="VISIT")
		{
			return false;
		}
	}

	if(MyLiveChat_GetLocalData("MLCSmart"))
	{
		if(new Date().getTime()/1000-(parseFloat(MyLiveChat_GetLocalData("MLCSmartTime"))||0)/1000 < MyLiveChat.SmartHideTimeout)
		{
			if(MyLiveChat.SmartUseMaxReject&&MyLiveChat.SmartMaxReject>0)
			{
				if( (parseInt(MyLiveChat_GetLocalData("MLCSmartRejectCount"))||0) >= MyLiveChat.SmartMaxReject)
				{
					return false;
				}
			}
			if(MyLiveChat.SmartUseMaxIgnore&&MyLiveChat.SmartMaxIgnore>0)
			{
				if( (parseInt(MyLiveChat_GetLocalData("MLCSmartIgnoreCount"))||0) >= MyLiveChat.SmartMaxIgnore)
				{
					return false;
				}
			}
		}
	}
		
	if(MyLiveChat.SmartUsePageCount&&MyLiveChat.VisitorUrls.length>=MyLiveChat.SmartPageCount)
	{
		return true;
	}
	
	if(MyLiveChat.SmartUseStayTime&&MyLiveChat.VisitorDuration>MyLiveChat.SmartStayTime)
	{
		return true;
	}
	
	if(MyLiveChat.SmartUsePageTime)
	{
		var pagetime=new Date().getTime()/1000-MyLiveChat.PageBeginTime/1000;
		if(pagetime>MyLiveChat.SmartPageTime)
		{
			return true;
		}
	}
	
	if(MyLiveChat.SmartUseVisitUrlFilter&&MyLiveChat.SmartVisitUrlFilter)
	{
		if(MyLiveChat_SmartIsMatch(window.location.href,MyLiveChat.SmartVisitUrlFilter))
			return true;
	}
	if(MyLiveChat.SmartUseEntryUrlFilter&&MyLiveChat.SmartEntryUrlFilter)
	{
		if(MyLiveChat_SmartIsMatch(MyLiveChat.VisitorEntryUrl,MyLiveChat.SmartEntryUrlFilter))
			return true;
	}
	if(MyLiveChat.SmartUseReferUrlFilter&&MyLiveChat.SmartReferUrlFilter)
	{
		if(MyLiveChat_SmartIsMatch(MyLiveChat.VisitorReferUrl,MyLiveChat.SmartReferUrlFilter))
			return true;
	}
	if(MyLiveChat.SmartUseKeywordsFilter&&MyLiveChat.SmartKeywordsFilter)
	{
		if(MyLiveChat.VisitorReferUrl)
		{
			var qs=MyLiveChat.VisitorReferUrl.split('#')[0].split('?')[1];
			if(qs)
			{
				qs=qs.split('&');
				for(var i=0;i<qs.length;i++)
				{
					var value=qs[i].split('=')[1];

					if(MyLiveChat_SmartIsMatch(value,MyLiveChat.SmartKeywordsFilter))
						return true;
					//alert([value,MyLiveChat.SmartKeywordsFilter])
				}
			}
		}
	}
	
	return false;
}

function MyLiveChat_SmartIsMatch(data,filter)
{
	if(!data)return false;
	if(!filter)return false;
	
	var arr=filter.toLowerCase().split(',');
	for(var i=0;i<arr.length;i++)
	{
		var item=arr[i].replace(/(^\s+)|(\s+$)/g,"");
		if(!item)continue;
		
		if(data.toLowerCase().indexOf(item)!=-1)
			return true;
	}
}

function MyLiveChat_HtmlEncode(text)
{
	if(!text)return "";
	return text.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\x22/g,"&quot;")
		.replace(/\x27/g,"&#39;").replace(/\n/g,"<br/>").replace(/\r/g,"");
}


function MyLiveChat_InvokeEvent(name,param)
{
	//known events : Loading,ShowInvite,HideInvite,ShowSmart,HideSmart,SmartPanelLoad,InvitePanelLoad
	if(window.HandleLiveChatEvent)
	{
		window.HandleLiveChatEvent(name,param);
	}
	if(MyLiveChat.SmartPanel&&MyLiveChat.SmartPanel.HandleLiveChatEvent)
	{
		MyLiveChat.SmartPanel.HandleLiveChatEvent(name,param);
	}
	if(MyLiveChat.InvitePanel&&MyLiveChat.InvitePanel.HandleLiveChatEvent)
	{
		MyLiveChat.InvitePanel.HandleLiveChatEvent(name,param);
	}
}

function MyLiveChat_ShowChatBox(disp)
{
	if(disp!="none")disp="";
	
	var divid="MyLiveChatScriptBox";
	
	var tagid="MyLiveChatChatBoxScriptTagID";
	var tag=document.getElementById(tagid);
	if(tag!=null)
	{
		if(!MyLiveChat.ChatBoxPanel)
		{
			if(window.jsml&&window.jsml.new_chatboxpanel)
			{
				window.jsml.new_chatboxpanel()
			}
		}
		return;
	}	

	var url=MyLiveChat.UrlBase+"ChatBox.aspx?HCCID="+MyLiveChat.HCCID;
	if(window.jsml)
	{
		url=url+"&jsmlcore=0";
		if(window.jsml.new_frameskin)
			url=url+"&jsmlskin=0";
		if(window.jsml.new_chatboxpanel)
			url=url+"&jsmlchatbox=0";
	}
	url=url+"&_ts="+new Date().getTime();
	
	tag=document.createElement("SCRIPT");
	tag.id=tagid;
	tag.src=url;

	document.body.insertBefore(tag,document.body.firstChild);
	
}

function MyLiveChat_PlaySound(url)
{
	if(/MSIE/.test(navigator.userAgent))
	{
		var bgs=document.createElement("BGSOUND");
		bgs.src=url;
		document.body.insertBefore(bgs,document.body.firstChild);
		return;
	}
	if(window.Audio)
	{
		var au=new window.Audio();
		au.autoplay=true;
		au.src=url;
		document.body.insertBefore(au,document.body.firstChild);
		return;
	}
}

function MyLiveChat_ShowSmart()
{
	var tagid="MyLiveChatSmartScriptTagID";
	var tag=document.getElementById(tagid);
	if(tag!=null)
	{
		if(!MyLiveChat.SmartPanel)
		{
			if(window.jsml&&window.jsml.new_smartpanel)
			{
				window.jsml.new_smartpanel()
			}
		}
		return;
	}	

	var url=MyLiveChat.UrlBase+"Smart.aspx?HCCID="+MyLiveChat.HCCID+"&SmartTemplate="+MyLiveChat.SmartTemplate;
	if(window.jsml)
	{
		url=url+"&jsmlcore=0";
		if(window.jsml.new_frameskin)
			url=url+"&jsmlskin=0";
		if(window.jsml.new_smartpanel)
			url=url+"&jsmlsmart=0";
	}
	url=url+"&_ts="+new Date().getTime();
	
	tag=document.createElement("SCRIPT");
	tag.id=tagid;
	tag.src=url;

	document.body.insertBefore(tag,document.body.firstChild);
	
	if(MyLiveChat.SmartPlaySound)
		MyLiveChat_PlaySound(MyLiveChat.SiteUrl+"Customization/Template/Smart_"+MyLiveChat.SmartSoundFile+".wav");

}
function MyLiveChat_AcceptSmart()
{
	MyLiveChat.SmartAccepted=true;
	MyLiveChat_SetLocalData("MLCSmart","Accept",MyLiveChat.SmartHideTimeout);
	MyLiveChat_SetLocalData("MLCSmartTime",new Date().getTime().toString(),MyLiveChat.SmartHideTimeout)
	MyLiveChat_OpenDialog("Smart");
	MyLiveChat_HideSmart();
}
function MyLiveChat_RejectSmart(istimeout)
{
	MyLiveChat.SmartRejected=true;
	var rkey=istimeout?"MLCSmartIgnoreCount":"MLCSmartRejectCount";
	var rcount=parseInt(MyLiveChat_GetLocalData(rkey))||0;
	rcount=rcount+1;
	MyLiveChat_SetLocalData(rkey,rcount.toString(),MyLiveChat.SmartHideTimeout);
	MyLiveChat_SetLocalData("MLCSmart","Reject",MyLiveChat.SmartHideTimeout);
	MyLiveChat_SetLocalData("MLCSmartTime",new Date().getTime().toString(),MyLiveChat.SmartHideTimeout)
	MyLiveChat_HideSmart();
}
function MyLiveChat_HideSmart()
{
	MyLiveChat_InvokeEvent("HideSmart");
	if(MyLiveChat.SmartPanel)
	{
		MyLiveChat.SmartPanel.dispose();
		MyLiveChat.SmartPanel=null;
	}
}

function MyLiveChat_ShowInvite()
{
	var tagid="MyLiveChatInviteScriptTagID";
	var tag=document.getElementById(tagid);
	if(tag!=null)
		return;

	var url=MyLiveChat.UrlBase+"Invite.aspx?HCCID="+MyLiveChat.HCCID+"&InviteTemplate="+MyLiveChat.InviteTemplate;
	if(window.jsml)
	{
		url=url+"&jsmlcore=0";
		if(window.jsml.new_frameskin)
			url=url+"&jsmlskin=0";
		if(window.jsml.new_invitepanel)
			url=url+"&jsmlinvite=0";
	}
	url=url+"&_ts="+new Date().getTime();
	
	tag=document.createElement("SCRIPT");
	tag.id=tagid;
	tag.src=url;

	document.body.insertBefore(tag,document.body.firstChild);
	
	if(MyLiveChat.InvitePlaySound)
	{
		MyLiveChat_PlaySound(MyLiveChat.SiteUrl+"Customization/Template/Invite_"+MyLiveChat.InviteSoundFile+".wav");
	}
}
function MyLiveChat_HideInvite()
{
	MyLiveChat_InvokeEvent("HideInvite");
	if(MyLiveChat.InvitePanel)
	{
		MyLiveChat.InvitePanel.dispose();
		MyLiveChat.InvitePanel=null;
	}
}

function MyLiveChat_AcceptInvite()
{
	try
	{
		window.LiveChatPrePopup=window.open("about:blank",'',MyLiveChat.DialogOption);
	}
	catch(x)
	{
		alert(PopupBlockedMsg);
		return;
	}
	clearTimeout(MyLiveChat.RequestTimerId);
	MyLiveChat_ChangeUrl("ACCEPT");
	MyLiveChat_HideInvite();
}
function MyLiveChat_RejectInvite()
{
	clearTimeout(MyLiveChat.RequestTimerId);
	MyLiveChat_ChangeUrl("REJECT")
	MyLiveChat_HideInvite();
}

function MyLiveChat_DelayRequest()
{
	MyLiveChat.LastInitTime=new Date().getTime();	
	MyLiveChat.NextRequestTimeout=18000*(1+Math.random());
	MyLiveChat_SetNextReqTimeout(MyLiveChat.NextRequestTimeout);
}

function MyLiveChat_SetNextReqTimeout(timer)
{
	var apimode='chatapi';
	
	if(apimode=="chatdialog")
		return;
	if(apimode=="chatdialogv2")
		return;
	
	if(timer)
	{
		MyLiveChat.NextRequestTime=MyLiveChat.LastInitTime+timer;
	}
	clearTimeout(MyLiveChat.RequestTimerId);
	MyLiveChat.RequestTimerId=setTimeout(MyLiveChat_NextRequest,555);
}

function MyLiveChat_NextRequest()
{
	var dt=new Date().getTime();
	
	//document.title=MyLiveChat.NextRequestTime-dt;
	
	if(dt<MyLiveChat.NextRequestTime)
	{
		MyLiveChat_SetNextReqTimeout();
		return;
	}
	
	if(!MyLiveChat.LastLoadTime&&!MyLiveChat.LastSyncTime)
	{
		MyLiveChat_ChangeUrl("VISIT");
		return;
	}
	
	if(!(MyLiveChat.localStorage||MyLiveChat.userDataBehavior))
	{
		MyLiveChat_ChangeUrl("VISIT");
		return;
	}
	
	
	var cppbt=parseInt(MyLiveChat_GetLocalData("MLCCPPBT"));
	if(MyLiveChat.PageBeginTime==cppbt)
	{
		if(cppbt==parseInt(MyLiveChat_GetLocalData("MLCCPAPT")))
		{
			MyLiveChat_ChangeUrl("VISIT");
			return;
		}
		if(dt-MyLiveChat.LastSyncTime>MyLiveChat.NextRequestTimeout*1.8)
		{
			MyLiveChat_ChangeUrl("VISIT");
			return;
		}
		MyLiveChat_SetNextReqTimeout();
		return;
	}
	
	MyLiveChat_SetLocalData("MLCCPAPT",String(MyLiveChat.PageBeginTime));
	
	var cprdt=parseInt(MyLiveChat_GetLocalData("MLCCPRDT"));
	if(!cprdt||dt-cprdt>MyLiveChat.NextRequestTimeout-1800)
	{
		MyLiveChat_ChangeUrl("VISIT");
		return;
	}
	
	MyLiveChat_SetNextReqTimeout(MyLiveChat.NextRequestTimeout);
	
	MyLiveChat_SyncFromCPR();
	MyLiveChat.ReSyncFormCPRTimerId=setTimeout(function()
	{
		if(cprdt!=parseInt(MyLiveChat_GetLocalData("MLCCPRDT")))
		{
			MyLiveChat_SyncFromCPR();
		}
	},MyLiveChat.NextRequestTimeout/2);
}

function MyLiveChat_SyncFromCPR()
{
	var arr=MyLiveChat.CPRFIELDS;
	for(var i=0;i<arr.length;i++)
		MyLiveChat[arr[i]]=MyLiveChat_CPRDecode(MyLiveChat_GetLocalData("MLC"+arr[i]));
	MyLiveChat_Initialize(true);
}
function MyLiveChat_CPRDecode(str)
{
	if(!str)
		return null;
	if(str=="null")return null;
	if(str=="true")return true;
	if(str=="false")return false;
	var prefix=str.substring(0,2);
	str=str.substring(2);
	if(prefix=="s:")
		return str;
	if(prefix=="n:")
		return parseFloat(str);
	if(prefix=="a:")
		return str.split('=|=');
	//document.title="mlc warning,unknown prefix:"+prefix;
	return null;
}

function MyLiveChat_CPREncode(val)
{
	if(val==null)
		return "null";
	var type=typeof(val);
	if(type=="boolean")
		return val?"true":"false";
	if(type=="string")
		return "s:"+val;
	if(type=="number")
		return "n:"+val;
	if(val instanceof Array)
		return "s:"+val.join('=|=');
	//document.title="mlc warning,unknown type:"+type;
	return null;
}

function MyLiveChat_GetSourceUrl()
{
	if(MyLiveChat.SourceUrl)
		return MyLiveChat.SourceUrl;
	return window.location.href;
}
function MyLiveChat_GetReferrer()
{
	var dr=document.referrer;
	if(!dr)return "";
	var chost=window.location.href.split("://")[1].split("/")[0];
	var rhost=dr.split("://")[1].split("/")[0];
	if(chost==rhost)return "";
	return dr;
}
function MyLiveChat_AppendToUrl(url)
{	
	var uadt=parseInt(MyLiveChat_GetLocalData("uadt"))||0;
	var uats=Math.floor( (new Date().getTime()-uadt)/1000 );
	uats=Math.max(1,Math.min(uats,3600*24*30));
	
	var contextdata="2:"+uats+"|"+(MyLiveChat.SourceContextData||"");
	
	url=url
		+"&UserKey="+escape(MyLiveChat.SourceKey||"")
		+"&Name="+escape(MyLiveChat.SourceName||"")
		+"&Email="+escape(MyLiveChat.SourceEmail||"")
		+"&Department="+escape(MyLiveChat.SourceDepartment||"")
		+"&Url="+escape(MyLiveChat_GetSourceUrl())
		+"&Referrer="+escape(MyLiveChat_GetReferrer())
		+"&Subject="+escape(MyLiveChat.SourceSubject||"")
		+"&Question="+escape(MyLiveChat.SourceQuestion||"")
		+"&CustomData="+escape(MyLiveChat.SourceCustomData||"")
		+"&ProductName="+escape(MyLiveChat.SourceProductName||"")
		+"&ProductKey="+escape(MyLiveChat.SourceProductKey||"")
		+"&ContextData="+escape(contextdata)
		+"&ScreenSize="+(screen.width+","+screen.height)
		+"&uats="+uats
		+"&_mv="+MyLiveChat.Version
		+"&_ts="+new Date().getTime();
	while(url.match(/\&[a-z]+\=\&/ig))url=url.replace(/\&[a-z]+\=\&/ig,"&");
	return url;
}
function MyLiveChat_ChangeUrl(_synctype)
{
	var tagid="MyLiveChatScriptTagID";
	var tag=document.getElementById(tagid);
	if(tag==null)
	{
		tag=document.createElement("SCRIPT");
		document.body.insertBefore(tag,document.body.firstChild);
	}

	var url=MyLiveChat.UrlBase+"livechat.aspx?&apimode=sync&HCCID="+MyLiveChat.HCCID
		+"&CCCustomerId="+MyLiveChat.CCCustomerId
		+"&Type="+_synctype;
		
	url=MyLiveChat_AppendToUrl(url);
	
	
	var newtag = document.createElement('SCRIPT');
    newtag.id = tagid;
    newtag.src = url;
    
    MyLiveChat.LastSyncTime=new Date().getTime();
    
	clearTimeout(MyLiveChat._checksynctimerid);
    MyLiveChat._checksynctimerid=setTimeout(function()
    {
		if(MyLiveChat.LastInitTime&&MyLiveChat.LastInitTime>MyLiveChat.LastSyncTime)
			return;
		MyLiveChat_DelayRequest();
    },48000);
	
    tag.parentNode.replaceChild(newtag,tag);
}

function MyLiveChat_GetDialogUrl(mode,chattype)
{
	if(MyLiveChat.SourceDepartment&&MyLiveChat.SmartClickOfflineItem=="Offline")
	{
		for(var i=0;i<MyLiveChat.Departments.length;i++)
		{
			if(MyLiveChat.Departments[i].Name==MyLiveChat.SourceDepartment&&!MyLiveChat.Departments[i].Online)
			{
				mode="Offline";
			}
		}
	}
	

	if(chattype!="inpage"&&!MyLiveChat.HasReadyAgents && 
        MyLiveChat.FeedbackBehavior=="Redirect" && MyLiveChat.FeedbackRedirectUrl)
	{
		return MyLiveChat.FeedbackRedirectUrl;
	}

	var url=MyLiveChat.PrivateChatUrl||(MyLiveChat.HomePage+"chat/chat.aspx");
	url=url.split('#')[0];
	url+=url.indexOf('?')==-1?"?":"&";
	
	if(chattype=="inpage"||location.href.indexOf("mlcmode=subsite")!=-1)url= MyLiveChat.UrlBase+"Redirect.aspx?";
	
	//url= MyLiveChat.UrlBase+"Redirect.aspx?";

	url=url+"HCCID="+MyLiveChat.HCCID
		+"&CCCustomerId="+MyLiveChat.CCCustomerId
		+"&Mode="+(mode||"Click")
		+"&ChatType="+(chattype||"default")
		
	url=MyLiveChat_AppendToUrl(url);
	return url;
}

function MyLiveChat_OpenDialog(mode)
{
	return window.open(MyLiveChat_GetDialogUrl(mode),'mylivechatdialog',MyLiveChat.DialogOption);
}


function MyLiveChat_ShowChatDialog(mode,chattype)
{
	var tagid="MyLiveChatDialogScriptTagID";
	var tag=document.getElementById(tagid);
	if(tag!=null)
		return;

	var url=MyLiveChat.UrlBase+"dialog.aspx?HCCID="+MyLiveChat.HCCID
		+"&CCCustomerId="+MyLiveChat.CCCustomerId
		+"&Mode="+(mode||"Click")
		+"&ChatType="+(chattype||"default")
	if(window.mlcdialog)
	{
		url=url+"&mlcdialog=0";
	}
	
	url=MyLiveChat_AppendToUrl(url);
	
	tag=document.createElement("SCRIPT");
	tag.id=tagid;
	tag.src=url;

	document.body.insertBefore(tag,document.body.firstChild);
}

function MyLiveChat_ShowChatWidget(mode)
{
	var tagid="MyLiveChatWidgetScriptTagID";
	var tag=document.getElementById(tagid);
	if(tag!=null)
		return;

	var url=MyLiveChat.UrlBase+"widget.aspx?HCCID="+MyLiveChat.HCCID+"&Mode="+(mode||"Click");
	if(window.mlcwidget)
	{
		url=url+"&mlcwidget=0";
	}
	url=url+"&_ts="+new Date().getTime();
	
	tag=document.createElement("SCRIPT");
	tag.id=tagid;
	tag.src=url;

	document.body.insertBefore(tag,document.body.firstChild);
}
function MyLiveChat_ShowInPageChat(mode)
{
	var tagid="MyLiveChatInPageScriptTagID";
	var tag=document.getElementById(tagid);
	if(tag!=null)
		return;
	var inpagetemplate = typeof(MyLiveChat_InlineChatButton)=="undefined"?"":(MyLiveChat_InlineChatButton||"");
	var inlinechattemplate = typeof(MyLiveChat_InlineChatTheme)=="undefined"?"":(MyLiveChat_InlineChatTheme||"");
	var url=MyLiveChat.UrlBase+"inline.aspx?HCCID="+MyLiveChat.HCCID+"&Mode="+(mode||"Click") + 
		"&InpageTemplate="+inpagetemplate+"&InlineChatTemplate=" + inlinechattemplate;
	if(window.jsml)
	{
		url=url+"&jsmlcore=0";
		if(window.jsml.new_frameskin)
			url=url+"&jsmlskin=0";
		if(window.jsml.new_inpagepanel)
			url=url+"&jsmlinpage=0";
	}
	url=url+"&_ts="+new Date().getTime();
	
	tag=document.createElement("SCRIPT");
	tag.id=tagid;
	tag.src=url;

	document.body.insertBefore(tag,document.body.firstChild);
}

function MyLiveChat_WriteOrSetHTML(html)
{
	var c=document.getElementById("MyLiveChatContainer");
	if(c)
		c.innerHTML=html;
	else
		document.write(html);
}

function MyLiveChat_Initialize(fromcpr)
{
	MyLiveChat.LastInitTime=new Date().getTime();
	
	MyLiveChat.ButtonImageUrl=MyLiveChat.HasReadyAgents?MyLiveChat.ButtonOnlineImage:MyLiveChat.ButtonOfflineImage;
	MyLiveChat.ButtonTooltip=MyLiveChat.HasReadyAgents?MyLiveChat.ButtonOnlineTooltip:MyLiveChat.ButtonOfflineTooltip;
	MyLiveChat.LinkHtmlCode=MyLiveChat.HasReadyAgents?MyLiveChat.LinkOnlineCode:MyLiveChat.LinkOfflineCode;
	MyLiveChat.LinkTooltip=MyLiveChat.HasReadyAgents?MyLiveChat.LinkOnlineTooltip:MyLiveChat.LinkOfflineTooltip;
	MyLiveChat.BoxHtmlCode=MyLiveChat.HasReadyAgents?MyLiveChat.BoxOnlineCode:MyLiveChat.BoxOfflineCode;
	MyLiveChat.BoxTooltip=MyLiveChat.HasReadyAgents?MyLiveChat.BoxOnlineTooltip:MyLiveChat.BoxOfflineTooltip;
	MyLiveChat.BoxPhotoUrl=MyLiveChat.HasReadyAgents?MyLiveChat.BoxOnlinePhoto:MyLiveChat.BoxOfflinePhoto;

	if(MyLiveChat.SmartCondition=="online")
	{
		if(!MyLiveChat.HasReadyAgents)
		{
			MyLiveChat.ShowSmart=false;
		}
	}

	MyLiveChat.CCCustomerId=null||MyLiveChat_GetLocalData("CCCustomerId");
	if(!MyLiveChat.CCCustomerId)
	{
		MyLiveChat.CCCustomerId=MyLiveChat.RandomID;
		MyLiveChat_SetLocalData("CCCustomerId",MyLiveChat.CCCustomerId,86400);
	}
	
	MyLiveChat_InvokeEvent("Initializing");
	
	if( ! MyLiveChat.SyncType )
	{
		MyLiveChat_SetNextReqTimeout(MyLiveChat.FirstRequestTimeout);
	}
	else if(MyLiveChat.SyncType=="VISIT")
	{
		var ntimeout=MyLiveChat.NextRequestTimeout;
		if(MyLiveChat.LastSyncTime&&!fromcpr)
		{
			ntimeout+=(new Date().getTime()-MyLiveChat.LastSyncTime)*2;
			if(ntimeout>23000)ntimeout=23000;
		}
		MyLiveChat_SetNextReqTimeout(ntimeout);
	}


	if(MyLiveChat.SyncType=="VISIT")
	{
		if(MyLiveChat.SyncStatus=="INVITE")
		{
			var pos=MyLiveChat.SyncResult.indexOf(',');
			var agentname=MyLiveChat.SyncResult.substring(0,pos);
			var agentmsg=MyLiveChat.SyncResult.substring(pos+1);
			if(agentmsg)
				MyLiveChat.InviteMessage=agentmsg;
			MyLiveChat.InviteMessage=MyLiveChat.InviteMessage.split("(AGENT)").join(agentname);
			
			MyLiveChat.HasInvited=true;
			
			if(MyLiveChat.InviteUseAgentPhoto)
			{
				MyLiveChat.InvitePhoto=MyLiveChat.UrlBase+"FindAgentPhoto.aspx?hccid="+MyLiveChat.HCCID+"&name="+escape(agentname);
			}
			
			if(MyLiveChat.ShowInvite)
			{
				MyLiveChat_InvokeEvent("ShowInvite");
				MyLiveChat_ShowInvite();
				MyLiveChat_HideSmart();
			}
			else
			{
				MyLiveChat_RejectInvite();
			}
		}
		else
		{
	        MyLiveChat_HideInvite();
		}
		
        if(!MyLiveChat.HasInvited)
        {
			if(MyLiveChat.ShowSmart&&MyMyLiveChat_SmartTriggers())
			{
				MyLiveChat_InvokeEvent("ShowSmart");
				MyLiveChat_ShowSmart();
			}
			else
			{
				MyLiveChat_HideSmart();
			}
		}
	}
	if(MyLiveChat.SyncType=="ACCEPT")
	{
		if(MyLiveChat.SyncStatus=="READY")
		{
			var url=MyLiveChat_GetDialogUrl("Invite")
			
			var win=window.LiveChatPrePopup;
			if(win!=null)
			{
				win.location.href=url;
				window.LiveChatPrePopup=null;
			}
			else
			{
				try
				{
					win=window.open(url,'',MyLiveChat.DialogOption);
				}
				catch(x)
				{
				}
				if(win==null)
				{
					alert(PopupBlockedMsg);
				}
			}
		}
		if(window.LiveChatPrePopup)
		{
			window.LiveChatPrePopup.close();
			window.LiveChatPrePopup=null;
		}
		if(MyLiveChat.SyncStatus=="EXPIRED")
		{
			
		}
		if(MyLiveChat.SyncStatus=="ERROR")
		{
			
		}

	}
	
	MyLiveChat_InvokeEvent("Loading");

	for(var i=0;i<MyLiveChat.LoadingHandlers.length;i++)
	{
		var handler=MyLiveChat.LoadingHandlers[i]
		handler(handler);
	}	
}

MyLiveChat.LoadingHandlers.push(function(funcself)
{
	var apimode='chatapi';
	var modedisp=MyLiveChat.FeedbackBehavior=="Hide"?(MyLiveChat.HasReadyAgents?"":"none"):"";

	if( ! MyLiveChat.SyncType )
	{
		if(funcself.Inited)return;
		funcself.Inited=true;
		
		if(MyLiveChat.ShowButton&&apimode=="chatbutton")
		{
			MyLiveChat_WriteOrSetHTML("<img id='MyLiveChatScriptButton' onclick='MyLiveChat_OpenDialog()' src='"+MyLiveChat.ButtonImageUrl
				+"' title='"+MyLiveChat_HtmlEncode(MyLiveChat.ButtonTooltip)+"' border='0' style='cursor:pointer;display:"+modedisp+"'>");
			MyLiveChat.LastButtonImageUrl=MyLiveChat.ButtonImageUrl;
		}
		if(MyLiveChat.ShowLink&&apimode=="chatlink")
		{
			MyLiveChat_WriteOrSetHTML("<a id='MyLiveChatScriptLink' onclick='MyLiveChat_OpenDialog()' title='"+MyLiveChat_HtmlEncode(MyLiveChat.LinkTooltip)+"' style='cursor:pointer;display:"+modedisp+"'>"+MyLiveChat.LinkHtmlCode+"</a>");
			MyLiveChat.LastLinkHtmlCode=MyLiveChat.LinkHtmlCode;
		}
		if(MyLiveChat.ShowBox&&apimode=="chatbox")
		{
			MyLiveChat_WriteOrSetHTML("<div id='MyLiveChatScriptBox'></div>");
			MyLiveChat_ShowChatBox(modedisp);
		}
		if(apimode=="chatinline")
		{
			MyLiveChat_ShowInPageChat();
		}
		if(apimode=="chatwidget")
		{
			MyLiveChat_ShowChatWidget();
		}
		if(apimode=="chatdialog")
		{
			MyLiveChat_ShowChatDialog();
		}
	}
	else
	{
		if(apimode=="chatbutton")
		{
			var btn=document.getElementById("MyLiveChatScriptButton");
			if(btn && MyLiveChat.LastButtonImageUrl!=MyLiveChat.ButtonImageUrl)
			{
				btn.style.display=modedisp;
				btn.setAttribute("title",MyLiveChat.ButtonTooltip||"");
				btn.setAttribute("src",MyLiveChat.ButtonImageUrl);
				MyLiveChat.LastButtonImageUrl=MyLiveChat.ButtonImageUrl;
			}
		}
		if(apimode=="chatlink")
		{
			var btn=document.getElementById("MyLiveChatScriptLink");
			if(btn && MyLiveChat.LastLinkHtmlCode!=MyLiveChat.LinkHtmlCode)
			{
				btn.style.display=modedisp;
				btn.setAttribute("title",MyLiveChat.LinkTooltip||"");
				btn.innerHTML=MyLiveChat.LinkHtmlCode;
				MyLiveChat.LastLinkHtmlCode=MyLiveChat.LinkHtmlCode;
			}
		}
		if(apimode=="chatbox")
		{
			var btn=document.getElementById("MyLiveChatScriptBox");
			if(btn)
			{
				MyLiveChat_ShowChatBox(modedisp);
			}
		}
	}

});

function MyLiveChat_CalcBodyPoint(mode, bp)
{
	if(!mode)mode="bottomright";
	if(!bp && bp!==0) bp = 5;
	
	var de=document.compatMode=="BackCompat"?document.body:document.documentElement;
	var bw=de.clientWidth;
	var bh=de.clientHeight;
	
	if(mode!="float")
	{
		var p=MyLiveChat_CalcPoint(mode,bw,bh);
		if(mode.indexOf("left")!=-1)
			p.left+=bp;
		if(mode.indexOf("right")!=-1)
			p.left-=bp;
		if(mode.indexOf("top")!=-1)
			p.top+=bp;
		if(mode.indexOf("bottom")!=-1)
			p.top-=bp;
		return p;
	}
	
	return MyLiveChat_CalcPoint(mode,bw,bh);
}
function MyLiveChat_CalcPoint(mode,w,h)
{
	switch(mode)
	{
		case "float":
		case "topleft":
			return {top:0,left:0};
		case "topcenter":
			return {top:0,left:Math.floor(w/2)}
		case "topright":
			return {top:0,left:w}
		case "middleleft":
			return {top:Math.floor(h/2),left:0};
		case "middlecenter":
			return {top:Math.floor(h/2),left:Math.floor(w/2)}
		case "middleright":
			return {top:Math.floor(h/2),left:w}
		case "bottomleft":
			return {top:h,left:0};
		case "bottomcenter":
			return {top:h,left:Math.floor(w/2)}
		case "bottomright":
			return {top:h,left:w}
		default:
			return {top:h,left:w}
	}
}
function MyLiveChat_MovePoint(src,dst)
{
	return dst;
}


//uniquekey - (userid/email/guid..etc)
function MyLiveChat_SetUserName(displayname,uniquekey)
{
	MyLiveChat.SourceName=displayname;
	MyLiveChat.SourceKey=uniquekey;
}
function MyLiveChat_SetEmail(email)
{
	MyLiveChat.SourceEmail=email;
}
function MyLiveChat_SetDepartment(department)
{
	MyLiveChat.SourceDepartment=department;
}
function MyLiveChat_SetSubject(subject)
{
	MyLiveChat.SourceSubject=subject;
}
function MyLiveChat_SetQuestion(question)
{
	MyLiveChat.SourceQuestion=question;
}
function MyLiveChat_SetCustomData(data)
{
	MyLiveChat.SourceCustomData=data;
}
function MyLiveChat_SetContextData(data)
{
	MyLiveChat.SourceContextData=data;
}
function MyLiveChat_SetProductName(name)
{
	MyLiveChat.SourceProductName=name;
}
function MyLiveChat_SetProductKey(key)
{
	MyLiveChat.SourceProductKey=key;
}

function MyLiveChat_OnUserIsOnline(isinit)
{
	var uadt=parseInt(MyLiveChat_GetLocalData("uadt"))||0;
	MyLiveChat_SetLocalData("uadt",String(new Date().getTime()))
	if(isinit!==true&&uadt&&new Date().getTime()-uadt>5*60*1000)
	{
		clearTimeout(MyLiveChat.RequestTimerId);
		MyLiveChat_ChangeUrl("VISIT");
	}
}

if(document.addEventListener)
{
	document.addEventListener("mouseover",MyLiveChat_OnUserIsOnline,false);
	document.addEventListener("keydown",MyLiveChat_OnUserIsOnline,false);
	window.addEventListener("focus",MyLiveChat_OnUserIsOnline,false);
	window.addEventListener("blur",MyLiveChat_OnUserIsOnline,false);
}
else
{
	document.attachEvent("mouseover",MyLiveChat_OnUserIsOnline);
	document.attachEvent("onkeydown",MyLiveChat_OnUserIsOnline);
	window.attachEvent("focus",MyLiveChat_OnUserIsOnline);
	window.attachEvent("blur",MyLiveChat_OnUserIsOnline);
}

MyLiveChat_OnUserIsOnline(true);



MyLiveChat_Initialize()

